package com.huarui.quotation.activemq;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import com.huarui.quotation.model.Quotation;

public class QuotationMessageSender {
	private JmsTemplate jmsTemplate;
	private QuotationMessageConverter   messageConverter;
	private Destination destination;
	public Destination getDestination() {
		return destination;
	}
	public void setDestination(Destination destination) {
		this.destination = destination;
	}
	public JmsTemplate getJmsTemplate() {
		return jmsTemplate;
	}
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}



	public QuotationMessageConverter getMessageConverter() {
		return messageConverter;
	}
	public void setMessageConverter(QuotationMessageConverter messageConverter) {
		this.messageConverter = messageConverter;
	}
	public void send( final Quotation quotation){
		
		
		jmsTemplate.send(destination, new MessageCreator() {
			@Override
			public Message createMessage(Session session) throws JMSException {
				return messageConverter.toMessage(quotation, session);
			}
		});
		
	}
	
}
